import request from '@/utils/request'

export const textbookApi = {
	// staff
	listMine(params) {
		return request({ url: '/api/textbooks/mine', method: 'get', params })
	},
	getById(id) {
		return request({ url: `/api/textbooks/${id}`, method: 'get' })
	},
	listAuthors(id) {
		return request({ url: `/api/textbooks/${id}/authors`, method: 'get' })
	},
	create(data) {
		return request({ url: '/api/textbooks', method: 'post', data })
	},
	update(id, data) {
		return request({ url: `/api/textbooks/${id}`, method: 'put', data })
	},
	remove(id) {
		return request({ url: `/api/textbooks/${id}`, method: 'delete' })
	},
	// 附件
	uploadAttachment(id, file, fileType = '证明材料') {
		const formData = new FormData()
		formData.append('file', file)
		formData.append('fileType', fileType)
		return request({ url: `/api/textbooks/${id}/attachments`, method: 'post', data: formData, headers: { 'Content-Type': 'multipart/form-data' } })
	},
	listAttachments(id) {
		return request({ url: `/api/textbooks/${id}/attachments`, method: 'get' })
	},
	deleteAttachment(id, attId) {
		return request({ url: `/api/textbooks/${id}/attachments/${attId}`, method: 'delete' })
	},
	downloadAttachment(id, attId) {
		return request({ url: `/api/textbooks/${id}/attachments/${attId}/download`, method: 'get', responseType: 'blob' })
	},
	// admin
	listAll(params) {
		return request({ url: '/api/textbooks/all', method: 'get', params })
	},
	listPending(params) {
		return request({ url: '/api/textbooks/pending', method: 'get', params })
	},
	review(id, data) {
		return request({ url: `/api/textbooks/${id}/review`, method: 'post', data })
	},
	stats(params) {
		return request({ url: '/api/textbooks/stats', method: 'get', params })
	}
} 